home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODF-Interest Archive / July 96 / Re Bug in FW_CStrings.1 < prev    next >
Encoding:
Internet Message Format  |  1996-07-26  |  2.6 KB  |  [TEXT/ttxt]

  1. Subject:     Re: Bug in FW_CStrings
  2. Sent:        7/25/96 4:20 PM
  3. Received:    7/25/96 3:41 PM
  4. From:        Greg Friedman, friedman@cognosis.com
  5. Reply-To:    ODF Interest, ODF-Interest@CILabs.ORG
  6. To:          OpenDoc Development Framework Discussion List, ODF-Interest@CILabs.
  7.  
  8. Kirk Swenson wrote:
  9. > There appears to be a bug in ODF's reference-counted string handling when
  10. > assigning from bounded strings (e.g. FW_CString32) to unbounded ones (e.g.
  11. > FW_CString).  It took a while to isolate, and I haven't pinpointed it
  12. > exactly, but the following code demonstrates it:
  13.  
  14. Kirk,
  15.  
  16. Thanks for the work you've done to narrow this bug down. The code snippet
  17. you provided illustrates the minimum number of steps necessary to create
  18. the problem:
  19.  
  20. 1. Allocate an unbounded/dynamic string.
  21. 2. Call a subroutine or enter a new block that does the following:
  22.     a. Declare a bounded string.
  23.     b. Assign the bounded string to the dynamic string.
  24.     c. Assign new data to the bounded string.
  25.     d. Exit the subroutine or current scope, causing the
  26.        destructor of the bounded string to execute.
  27.  
  28. The dynamic string is now corrupted or on the verge of corruption. The
  29. problem is caused by the fact that when the static string is assigned to
  30. the dynamic string (step b), the dynamic string acquires the static strings
  31. representation/buffer. This buffer is allocated as bytes on the stack. When
  32. new data is assigned to the bounded string, ODF clones the data, and
  33. assigns the new representation to the bounded string. The dynamic string is
  34. still using the stack-based buffer which is a data member of the bounded
  35. string. When the bounded string goes out of scope, the stack shrinks, and
  36. the dynamic string is left pointing at whatever unrelated stuff is in the
  37. stack space formerly occupied by the bounded string.
  38.  
  39. The good news is that I've fixed the problem. The bad news is that the fix
  40. is in the shared library, and won't be released until ODF 2 ships. The fix
  41. alters the way that string representations are cloned. With the new
  42. implementation, the bounded string declared in the subroutine would have
  43. maintained ownership of its buffer, and the dynamic string would acquire
  44. the newly allocated buffer. Because we use double indirection, this will
  45. not have a negative impact on the case where there are more than 2 clients
  46. of a string representation.
  47.  
  48. Until ODF 2 ships, I suggest you either use dynamic strings in all cases,
  49. or avoid the specific case you came across. Thanks again for taking the
  50. time to track the problem down.
  51.  
  52. Greg Friedman.
  53. ODF Engineering.
  54.  
  55.  
  56. ___________________________________________________________
  57.  Greg Friedman       ODF Engineering        Apple Computer
  58.  
  59.  
  60.